package fourthQuestion;

import java.io.*;
import java.net.Socket;

public class Client {

    public static void main(String[] args) {
        Socket socket = null;
        OutputStream os = null;
        FileInputStream fis = null;
        PrintWriter pw = null;
        BufferedReader br = null;
        try {
            socket = new Socket("localhost", 8000);
            os = socket.getOutputStream();
            String path = "E:/蒋金鑫/MyPic/img01.JPG";
            fis = new FileInputStream(new File(path));

            pw = new PrintWriter(socket.getOutputStream(), true);
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            pw.println(path);

            byte[] bytes = new byte[1024];
            int temp = 0;
            while ((temp = fis.read(bytes)) != -1) {
                os.write(bytes, 0, temp);
                os.flush();
            }


        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
